const cloud = require('wx-server-sdk')
const TcbRouter = require('tcb-router')
import queryWatchData from './router/modules/queryData'

cloud.init({
    env: 'j-1g278wytc94978ae'
})

exports.main = async (event, context) => {
    const log = cloud.logger();
    const app = new TcbRouter({ event });
    const db = cloud.database();
    const _ = db.command;

    const collectionName = event.collection_name;
    const params = event.params;
    
    app.use(async (ctx, next) => {
        ctx.data = {};
        await next();
    });

    app.router('musicList', async (ctx, next) => {
        return ctx.body = queryWatchData(params,db,collectionName)
        // return ctx.body = await db.collection(collectionName).get()
    })

    return app.serve();
}